<template>
  <div class="mine">
    <div class="header">
      <div class="back" style="height: 180px"></div>
      <div class="card">
        <p class="name">{{ list.username }}</p>
        <div class="flex">
          <div class="flex_item">
            <p class="word">账户余额</p>
            <p class="number">{{ balance }}</p>
          </div>
          <div class="flex_item">
            <button class="top-up" @click="showPopup">充值</button>
          </div>
        </div>
      </div>
    </div>
    <div class="JPG">
      <img
        :src="list.userFace != '' ? list.userFace : photourl"
        width="100%"
        height="100%"
      />
    </div>
    <div class="address">
      <van-cell title="常用地址" is-link to="/manager/address" icon="phone-o" />
      <van-cell title="联系我们" is-link icon="location-o" />
    </div>
    <div class="down" style="margin: 16px">
      <van-button
        color="linear-gradient(90deg, #7579ff, #bf73ff)"
        round
        size="large"
        @click="offline"
        >退出登录</van-button
      >
    </div>
    <van-popup
      position="bottom"
      v-model="show"
      round
      closeable
      :style="{ height: '30%' }"
    >
      <div class="topUp">充值</div>
      <van-cell-group>
        <van-field
          v-model="money"
          label="充值金额"
          placeholder="请输入充值金额"
        />
        <div style="margin: 16px">
          <button class="moneyTijiao" @click="sumbitMoney">提交</button>
        </div>
      </van-cell-group>
    </van-popup>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
import { get, post } from "@/http/axios";
import { Toast } from "vant";
export default {
  data() {
    return {
      photourl:
        "http://121.199.29.84:8888/group1/M00/00/50/rBD-SWDixYOASajcAAAteDVkRqQ289.jpg",
      balance: "",
      id: "",
      show: false,
      money: "",
      list: "",
    };
  },
  created() {
    this.userInfo();
  },
  computed: {
    //使⽤对象展开运算符将此对象混⼊到外部对象中
    ...mapState("user", ["token"]),
  },
  methods: {
    async sumbitMoney() {
      let data = {
        customerId: this.id,
        money: this.money,
      };
      if (data.money > 1000) {
        Toast("单次最大充值为1000");
      } else {
        await get("/account/recharge", data);
        this.userInfo();
        this.show = false;
      }
    },
    async userInfo() {
      let res1 = await get("/user/info?token=" + localStorage.getItem("token"));
      this.balance = res1.data.data.balance;
      this.id = res1.data.data.id;
      // console.log(res1);
      this.list = res1.data.data;
    },
    offline() {
      this.$router.push({ path: "/login" });
    },
    showPopup() {
      this.money = "";
      this.show = true;
    },
  },
};
</script>

<style scoped>
.top-up {
  border-radius: 30px;
  width: 80%;
  height: 100%;
  background-image: linear-gradient(90deg, #7579ff, #bf73ff);
  color: white;
  border: none;
}
.mine .address {
  position: relative;
  top: 130px;
  font-size: 15px;
  text-align: left;
  box-shadow: 2px 2px 2px #c073ff65;
}
div.back {
  height: 180px;
  background-image: linear-gradient(90deg, #7579ff, #bf73ff);
  border-bottom-left-radius: 50%;
  border-bottom-right-radius: 50%;
}
.flex {
  display: flex;
  justify-content: space-around;
  margin-top: 1em;
}
.flex_item {
  width: 24%;
  height: 40px;
  text-align: center;
  cursor: pointer;
}

.card {
  width: 80%;
  height: 170px;
  background-color: #fff;
  position: absolute;
  top: 170px;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.8;
  box-shadow: 0 0 10px #ccc;
  border-radius: 8px;
  padding: 0 1em;
}

.JPG {
  margin-top: -95px;
  width: 95px;
  height: 95px;
  border-radius: 50%;
  background-color: #bf73ff;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
}
.JPG img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}
.name {
  width: 50%;
  margin: 0 auto;
  margin-top: 3.5em;
  text-align: center;
}
.flag {
  color: #bf73ff;
  width: 50%;
  margin: 0 auto;
  margin-top: 0.5em;
  text-align: center;
  font-size: 12px;
}
.word {
  font-size: 15px;
  color: #999;
  margin: 0;
}
.number {
  font-size: 22px;
  margin-top: 2px;
  color: #bf73ff;
}
::v-deep .van-button {
  margin-top: 230px;
}
.topUp {
  text-align: center;
  line-height: 60px;
}
.moneyTijiao {
  /* 按钮定位 */
  position: absolute;
  left: 19px;
  top: 65px;
  border-radius: 30px; /*  设置按钮圆角效果*/
  width: 90%; /*  设置按钮宽度*/
  height: 45px; /*  设置按钮高度*/
  background-color: rgba(182, 38, 201, 0.63); /*  设置按钮背景颜色*/
  color: white;
  border: none; /*  设置按钮无边框*/
}
</style>